package com.spirng.leetcode.day05;

import java.util.*;

public class Test49 {
    public static void main(String[] args) {
        String s="eat";
        char[] array = s.toCharArray();
        Arrays.sort(array);
        System.out.println(array);
    }
    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String,List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] array = str.toCharArray();
            Arrays.sort(array);
            String s = Arrays.toString(array);
            List<String> list = map.getOrDefault(s, new ArrayList<String>());
            list.add(str);
            map.put(s,list);
        }
        ArrayList<List<String>> list = new ArrayList<>();
        for (Map.Entry<String, List<String>> stringListEntry : map.entrySet()) {
            list.add(stringListEntry.getValue());
        }
        return list;
    }
}
